package com.glodon.paas.monitor.server.biz.service.impl;

import java.util.ArrayList;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.glodon.paas.monitor.server.biz.domain.MonitorUserEntity;
import com.glodon.paas.monitor.server.biz.mapper.MonitorUserMapper;
import com.glodon.paas.monitor.server.biz.service.MonitorUserService;
import com.glodon.paas.monitor.server.exception.MonitorException;

@Service("monitorUserService")
public class MonitorUserServiceImpl implements MonitorUserService {

	@Autowired
	private MonitorUserMapper	monitorUserMapper;

	@Override
	public int deleteByPrimaryKey(Long id) throws MonitorException {
		if (null == id) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID, "deleteByPrimaryKey User id is null!");
		}
		return monitorUserMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(MonitorUserEntity record) throws MonitorException {
		if (null == record) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID, "insert User record is null!");
		}
		return monitorUserMapper.insert(record);
	}

	@Override
	public int insertSelective(MonitorUserEntity record) throws MonitorException {
		if (null == record) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID, "insertSelective User record is null!");
		}
		return monitorUserMapper.insertSelective(record);
	}

	@Override
	public MonitorUserEntity selectByPrimaryKey(Long id) throws MonitorException {
		if (null == id) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID, "selectByPrimaryKey User id is null!");
		}
		return monitorUserMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(MonitorUserEntity record) throws MonitorException {
		if (null == record || null == record.getId()) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"updateByPrimaryKeySelective User record is null!");
		}
		return monitorUserMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(MonitorUserEntity record) throws MonitorException {
		if (null == record || null == record.getId()) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"updateByPrimaryKey User record is null!");
		}
		return monitorUserMapper.updateByPrimaryKey(record);
	}

	@Override
	public MonitorUserEntity selectByUserName(String userName) throws MonitorException {
		if (null == userName) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"selectByUserName User userName is null!");
		}
		return monitorUserMapper.selectByUserName(userName);
	}

	public ArrayList<MonitorUserEntity> queryMonitorUser(MonitorUserEntity record) throws MonitorException {

		return monitorUserMapper.queryMonitorUser(record);

	}

	public MonitorUserEntity loginByUserNameAndPassword(String userName, String password) throws MonitorException {
		if (StringUtils.isBlank(userName) || StringUtils.isBlank(password)) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"selectByUserName User userName or password null!");
		}
		return monitorUserMapper.loginByUserNameAndPassword(userName, password);
	}
}
